<template>
	<view class="fui-wrap">
		<block v-if="err">
			<fui-result type="fail" title="操作失败" :descr="err" :paddingTop="300">
				<fui-button @click="$reLaunch('index/index')" width="400rpx" height="84rpx" text="返回主页" type="success" bold :margin="['48rpx','0','24rpx']"></fui-button>
			</fui-result>
		</block>
		<block v-else>
			<fui-list>
				<fui-list-cell v-for="(item,index) in list" arrow :key="index" @click="goParking(item)">
					<view class="line">
						<fui-text :text="item.title" type="black" size="32" block fontWeight="bolder"></fui-text>
						<view style="margin-top: 20rpx;display: flex;justify-content: space-between;width: 100%;">
							<fui-text text="相机：" type="black" size="28"></fui-text>
							<fui-tag :text="`在线:${item.barrier_online[1]}`" type="success"></fui-tag>
							<fui-tag v-if="item.barrier_online[0]>0" :text="`离线:${item.barrier_online[0]}`" type="danger"></fui-tag>
							<fui-tag v-else :text="`离线:${item.barrier_online[0]}`" background="#CCCCCC" color="#fff"></fui-tag>
						</view>
						<view style="margin-top: 20rpx;">
							<fui-text v-if="item.trigger_time" :text="`最近触发相机：${formatDuration(item.trigger_time)}前`" type="black" size="28" block></fui-text>
							<view style="display: flex;align-items: center;" v-else>
								<fui-text text="最近触发相机：" type="black" size="28" block></fui-text>
								<fui-tag text="未启用" type="danger"></fui-tag>
							</view>
						</view>
						<view style="margin-top: 20rpx;">
							<fui-text v-if="item.pay_time" :text="`最近在线支付：${formatDuration(item.pay_time)}前`" type="black" size="28" block></fui-text>
							<view style="display: flex;align-items: center;" v-else>
								<fui-text text="最近在线支付：" type="black" size="28" block></fui-text>
								<fui-tag text="未开通" type="danger"></fui-tag>
							</view>
						</view>
					</view>
				</fui-list-cell>
			</fui-list>
			<filter :param="param" @confirm="doSubmit"></filter>
			<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		</block>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {formatDuration} from '@/utils/util.js';
	import filter from '@/components/common/filter.vue';
	export default {
		components:{
			filter:filter
		},
		data() {
			return {
				baseUrl:baseUrl,
				err:'',
				list:[],
				page:1,
				endData:false,
				param:{
					title:''
				},
				showPopup:false
			}
		},
		onLoad(e) {
			this.getList();
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			formatDuration,
			...methods,
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			getList:function(callback=false){
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				this.$get('admin/index/parking',{
					...this.param,
					page:this.page
				},true).then(res=>{
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				}).catch(e=>{
					this.err=e.msg;
				});
			},
			goParking:function(item){
				this.$post('admin/index/login',{parking_id:item.id},true,true).then(res=>{
					this.$navigateTo('parking/index',1500);
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.line{
	width: 80%;
}
</style>